package com.ruoyi.algorithm.controller;

import com.ruoyi.algorithm.entity.TableStruct;
import com.ruoyi.algorithm.service.impl.UserTableStructServiceImpl;
import com.beihu.sightplus.common.response.ErrorMsgType;
import com.beihu.sightplus.common.response.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：yanfa-03
 * @date ：Created in 2021/7/12/17:19
 * @description ：用户表结构关联表控制器
 * @version: 1.0
 */
@RestController
@RequestMapping("userTableStruct")
@Api(tags = {"用户表结构关联表控制器"})
public class UserTableStructController {

    @Autowired
    private UserTableStructServiceImpl userTableStructService;

    @PutMapping("insertUserTableStructs")
    @ApiOperation("插入表结构用户关联信息")
    public ResultData<?> insertUserTS(Long userId) {
        if (userId == null || userId.equals(0L)) {
            userId = 11111111111111111L;
        }
        userTableStructService.insertByUserIdAndTableStructs(userId);
        return ResultData.success();
    }

    @PostMapping("editUserTableStructs")
    @ApiOperation("编辑表结构用户关联信息")
    public ResultData<?> editTableStructs(@RequestBody List<TableStruct> targetList) {
        Long userId = 11111111111111111L;
        if (userTableStructService.updateTableStructByID(userId, targetList)) {
            return ResultData.success();
        } else return ResultData.error(ErrorMsgType.Fail);
    }
}
